package cn.com.huak.www.sell.converter;

import cn.com.huak.www.sell.dataObject.OrderMaster;
import cn.com.huak.www.sell.dto.OrderDTO;
import cn.com.huak.www.sell.enums.ResultEnum;
import cn.com.huak.www.sell.exception.OrderException;
import org.springframework.beans.BeanUtils;

import javax.persistence.criteria.Order;
import java.util.List;
import java.util.stream.Collectors;

/**
 *  OrderMaster 转成 OrderDTO转换器
 * @author huak@wanggang
 * @date 2019/1/1 20:49
 */
public class OrderMaster2OrderDTOConverter {

    /* 单个OrderMaster转成OrderDTO */
    public static OrderDTO convert(OrderMaster orderMaster) {
        if (null == orderMaster) {
            throw new OrderException(ResultEnum.ORDER_ERROR);
        }
        OrderDTO orderDTO = new OrderDTO();
        BeanUtils.copyProperties(orderMaster, orderDTO);
        return orderDTO;
    }

    /* 多个orderMaster转成orderDTO */
    public static List<OrderDTO> convert(List<OrderMaster> orderMasters) {
        if(null == orderMasters){
            throw new OrderException(ResultEnum.ORDER_ERROR);
        }
        return orderMasters.stream().map(e -> convert(e)).collect(Collectors.toList());
    }
}